package input;

import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

public class InputStreamOwn extends ObjectInputStream{

    public InputStreamOwn(InputStream in) throws IOException {
        super(in);
    }
    public	static int counter =0; 

	 protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	      
		 System.out.println("oSC " +counter++);
		   ObjectStreamClass resultClassDescriptor = super.readClassDescriptor(); // initially streams descriptor
	        @SuppressWarnings("rawtypes")
			Class localClass = Class.forName(resultClassDescriptor.getName()); // the class in the local JVM that this descriptor represents.
	        if (localClass == null) {
	            System.out.println("No local class for " + resultClassDescriptor.getName());
	            return resultClassDescriptor;
	        }
	        ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
	        if (localClassDescriptor != null) { // only if class implements serializable
	            final long localSUID = localClassDescriptor.getSerialVersionUID();
	            final long streamSUID = resultClassDescriptor.getSerialVersionUID();
	            if (streamSUID != localSUID) { // check for serialVersionUID mismatch.
	                final StringBuffer s = new StringBuffer("Overriding serialized class version mismatch: ");
	                s.append("local serialVersionUID = ").append(localSUID);
	                s.append(" stream serialVersionUID = ").append(streamSUID);
	                Exception e = new InvalidClassException(s.toString());
	                System.out.println("Potentially Fatal Deserialization Operation. " + e);
	                resultClassDescriptor = localClassDescriptor; // Use local class descriptor for deserialization
	                
	            }
	        }
	        System.out.println("test");
	        return resultClassDescriptor;
	    }

}
